package org.mspring.platform.dao.support;

import java.util.HashMap;
import java.util.Map;

public class QueryAppender {
    private Map<String, String> orders = new HashMap();
    private Map<String, Object> conditions = new HashMap();

    public boolean isConditionsEmpty() {
        return this.conditions.isEmpty();
    }

    public boolean isOrdersEmpty() {
        return this.orders.isEmpty();
    }

    public Map<String, Object> getConditions() {
        return this.conditions;
    }

    public Map<String, String> getOrders() {
        return this.orders;
    }

    public QueryAppender asc(String field) {
        this.orders.put(field, "ASC");
        return this;
    }

    public QueryAppender desc(String field) {
        this.orders.put(field, "DESC");
        return this;
    }

    public QueryAppender equal(String field, Object value) {
        this.conditions.put(field + " = ", value);
        return this;
    }

    public QueryAppender notEqual(String field, Object value) {
        this.conditions.put(field + " <> ", value);
        return this;
    }

    public QueryAppender greatThan(String field, Object value) {
        this.conditions.put(field + " > ", value);
        return this;
    }

    public QueryAppender lessThan(String field, Object value) {
        this.conditions.put(field + " < ", value);
        return this;
    }

    public QueryAppender greatThanOrEqual(String field, Object value) {
        this.conditions.put(field + " >= ", value);
        return this;
    }

    public QueryAppender lessThanOrEqual(String field, Object value) {
        this.conditions.put(field + " <= ", value);
        return this;
    }

    public QueryAppender like(String field, Object value) {
        this.conditions.put(field + " LIKE ", value);
        return this;
    }

    public QueryAppender between(String field, Object begin, Object end) {
        this.conditions.put(field + " BETWEEN ", new Object[] { begin, end });
        return this;
    }

    public QueryAppender in(String field, Object value) {
        this.conditions.put(field + " IN ", value);
        return this;
    }
}